#!/usr/bin/perl

use Test;
BEGIN { plan tests => 2}

$basedir = $0;  $basedir =~ s|(.*)/[^/]*|$1|;

system "chmod +x wait";

# Start the process to be traced.
if(($pid=fork())==0){
    exec "runcon -t test_ptrace_traced_t $basedir/wait";
    exit;
}

sleep 1; # Give the process a moment to initialize.

# Verify that the nottracer domain cannot attach to the process.
# Should fail on the ptrace permission check.
$result = system "runcon -t test_ptrace_nottracer_t $basedir/ptrace $pid";
ok($result); # we expect this to fail.

# Verify that the tracer domain can trace to the process.
$result = system "runcon -t test_ptrace_tracer_t $basedir/ptrace $pid";
ok($result, 0); 

# Kill the process.
kill KILL,$pid;

exit;
